<template>
    <view>
        <!-- pages/activity_detail/activity_detail.wxml -->

        <view class="contain" v-if="datalist.length > 0">
            <image class="banner" mode="aspectFill" :src="special_image ? special_image : minImgDoc + 'couse_bg.png'" v-if="special_image"></image>
            <view class="detail" :style="special_image ? 'margin-top:375rpx' : 'margin-top:0rpx'">
                <view class="c-nav">
                    <view class="courses-name">
                        {{ thread.subject }}
                        <text v-if="special_activity.class && special_activity.class != 'undefined'">{{ special_activity.class }}</text>
                    </view>
                </view>

                <view class="c-header">
                    <view class="info">
                        <view class="time_content">
                            <image class="small_icon" :src="minImgDoc + 'join_time.png'"></image>
                            <view>报名截止：</view>
                            <view class="time">{{ special_activity.expiration != 0 ? special_activity.expiration : '不限' }}</view>
                        </view>
                        <view class="count_content">
                            <image class="small_icon" :src="minImgDoc + 'join_count.png'"></image>
                            <view>已报：</view>
                            <view class="count">{{ special_activity.applynumber }}/{{ special_activity.number }}人</view>
                        </view>
                    </view>
                </view>

                <view class="teacher-list">
                    <view class="mi_top">
                        <view class="fl mi_head">
                            <image :src="userAvatar + datalist[0].authorid"></image>
                        </view>
                        <view class="fl mi_msg">
                            <view class="mi_nick">{{ datalist[0].nickname ? datalist[0].nickname : datalist[0].author }}</view>
                            <view class="mi_label">
                                <text class="mi_ca">2小时前</text>
                            </view>
                        </view>
                    </view>
                </view>

                <view class="d_content">
                    <view class="detail_cell">
                        <view class="l_title">活动时间</view>
                        <rich-text class="l_message" :nodes="special_activity.starttimefrom + ' 至 ' + special_activity.starttimeto"></rich-text>
                    </view>
                    <view class="detail_cell">
                        <view class="l_title">活动地点</view>
                        <view class="l_message">{{ special_activity.place }}</view>
                    </view>
                    <view class="detail_cell">
                        <view class="l_title">活动介绍</view>
                        <rich-text class="l_message" :nodes="datalist[0].message"></rich-text>
                    </view>
                    <view class="detail_cell">
                        <view class="l_title">性别</view>
                        <view class="l_message">{{ special_activity.gender == 1 ? '男' : special_activity.gender == 2 ? '女' : '不限' }}</view>
                    </view>
                    <view class="detail_cell last-cell">
                        <view class="ac-join-c">
                            <view class="l_title">已报名（{{ special_activity.applynumber }}/{{ special_activity.number }}）</view>
                            <view class="j-m-c" v-if="member_uid == special_activity.uid || member_uid == 1">
                                <view class="join-manage" @tap="activityManage">报名管理</view>
                            </view>
                        </view>

                        <view class="l_student">
                            <block v-for="(item, index) in applylist" :key="index">
                                <view class="mi_head head-top">
                                    <image :src="item.avatar"></image>
                                </view>
                            </block>
                        </view>
                    </view>
                </view>
                <view :class="'join-btn ' + (isActivity ? '' : 'join-gray')" @tap="joinActivity">
                    <block v-if="special_activity.closed == 1">已截止</block>
                    <block v-else>
                        {{ isActivity ? '报名参加' : '取消报名' }}
                    </block>
                </view>
            </view>

            <view class="grayRow replyInfo">
                <view></view>
                <view class="sortTip" @tap="showSort">{{ listSortType }}</view>

                <view class="shortListContain" v-if="sortListShow">
                    <image :src="minImgDoc + 'sortList.png'" mode="top" class="shortList"></image>
                    <view class="sortType sortTypeF" @tap.stop.prevent="sortClick" id="2">
                        <view>默认顺序</view>
                        <image class="sortCheck" :src="minImgDoc + 'check.png'" v-if="sortdefault"></image>
                    </view>
                    <view class="sortType" id="1" @tap.stop.prevent="sortClick">
                        <view>按时间</view>
                        <image class="sortCheck" :src="minImgDoc + 'check.png'" v-if="!sortdefault"></image>
                    </view>
                </view>
            </view>

            <view class="reply">
                <block v-for="(item, index) in datalist" :key="index">
                    <view class="replyCell" :id="item.pid" v-if="index != 0" @tap="cellClick">
                        <view class="replyinfo-c">
                            <view class="replyerInfo">
                                <image class="avatar" :src="userAvatar + item.authorid"></image>
                                <view class="auther_info">
                                    <view class="username fontWeight">
                                        {{ item.nickname ? item.nickname : item.username }}
                                    </view>
                                    <rich-text class="retime" :nodes="item.dateline"></rich-text>
                                </view>
                            </view>
                        </view>

                        <view class="messageView">
                            <rich-text class="message" :nodes="item.message"></rich-text>
                            <view class="attachlist" v-if="item.attachments">
                                <view :class="'attachementView ' + (item.imageA.length == 0 && item.videoA.length == 1 ? 'singleVideo' : '')" v-if="item.attachments">
                                    <block v-for="(attItem, imgIndex) in item.imageA" :key="imgIndex">
                                        <image
                                            :class="'attachement ' + (item.imageA.length == 1 && item.videoA.length == 0 ? 'signle-image' : '')"
                                            :mode="item.imageA.length + item.videoA.length == 1 ? 'widthFix' : 'aspectFill'"
                                            :src="attItem.newUrl"
                                            :id="imgIndex"
                                            :data-cellindex="index"
                                            @tap.stop.prevent="lookImage"
                                        ></image>
                                    </block>

                                    <block v-for="(video, aidx) in item.videoA" :key="video.aid">
                                        <image @tap.stop.prevent="clickVideo" :id="video.newUrl" class="attachement" :src="minImgDoc + 'videoPlace.png'"></image>
                                    </block>
                                </view>
                                <block v-for="(audio, index1) in item.audioA" :key="attItem.aid">
                                    <!-- parse <template is="audio_player" :data="...audio.toolUse,minImgDoc"/> -->
                                    <block name="audio_player">
                                        <view class="audio-playView">
                                            <image
                                                :src="is_play && currentAudio == attachment ? minImgDoc + 'audio_play.png' : minImgDoc + 'audio_paused.png'"
                                                class="audio-icon audio-play"
                                                :data-listindex="listIndex"
                                                @tap.stop.prevent="audio_play"
                                                :id="attachment"
                                            ></image>
                                            <view class="control-process">
                                                <text class="current-process">
                                                    <block v-if="current_process.length > 0 && currentAudio == attachment">
                                                        {{ current_process }}
                                                    </block>
                                                    <block v-else>00:00</block>
                                                </text>

                                                <text class="total-process">
                                                    <block>
                                                        {{ total_process }}
                                                    </block>
                                                </text>
                                                <slider
                                                    class="slider"
                                                    @change="hanle_slider_change"
                                                    @touchstart="handle_slider_move_start"
                                                    @touchend="handle_slider_move_end"
                                                    min="0"
                                                    block-size="12"
                                                    block-color="#6199fd"
                                                    :max="slider_max"
                                                    activeColor="#5abf39"
                                                    backgroundColor="rgb(153,153,153,0.4)"
                                                    :value="currentAudio == attachment ? slider_value : 0"
                                                />
                                            </view>
                                        </view>
                                    </block>
                                </block>
                            </view>
                        </view>

                        <view class="flowerAndDiscuss">
                            <!-- <image src="{{item.issupport==1?minImgDoc+'answer_agreed.png':minImgDoc+'answer_agree.png'}}" class='workButton' catchtap='sendFlower' id="{{index}}"></image> -->
                            <view class="support" @tap.stop.prevent="sendFlower" :id="index">
                                <image src="/static/image/support.png"></image>
                                <view class="support-count">{{ item.postreview.support ? item.postreview.support : 0 }}</view>
                            </view>
                            <image :src="minImgDoc + 'work_discuss.png'" class="workButton" @tap.stop.prevent="replyWork" :id="item.pid"></image>
                        </view>

                        <view class="workReply" v-if="item.comments">
                            <block v-for="(wreply, index1) in item.comments" :key="wreply.id">
                                <view class="workReplyText">
                                    <text class="workReplyAuthor">{{ wreply.nickname ? wreply.nickname : wreply.author }}：</text>
                                    {{ wreply.comment }}
                                </view>
                            </block>
                            <view
                                @tap="commentMore"
                                class="commentMore"
                                :data-index="index"
                                :data-pid="item.pid"
                                v-if="commentMoreLock[item.pid] !== false && datalist[index].comments.length >= 5"
                            >
                                查看更多>
                            </view>
                        </view>
                    </view>
                </block>
            </view>

            <view class="noMoreView">没有更多了~</view>
        </view>

        <!-- 底部栏 -->
        <view class="toolbar">
            <view class="input-area" @tap.stop.prevent="replyText">请输入内容</view>
            <button open-type="share" :plain="true" @tap="share">
                <image class="shareIcon" :src="minImgDoc + 'course_share.png'"></image>
                <text class="shareText">分享</text>
            </button>
        </view>

        <activity_joinMask @joinSucceed="joinSucceed" :acPostData="acPostData" :joinShow="joinShow" :specialActivity="special_activity"></activity_joinMask>
    </view>
</template>

<script>
const detailUrl = require('../../config').detailUrl;

const baseUrl = require('../../config').baseUrl;

const pollvoteUrl = require('../../config').pollvoteUrl;

const collectUrl = require('../../config').collectUrl;

const sendFlowerUrl = require('../../config').sendFlowerUrl;

const joinClassUrl = require('../../config').joinClassUrl;

const bestanswerUrl = require('../../config').bestanswerUrl;

const commentMoreUrl = require('../../config').commentMoreUrl;

const activityAppliesUrl = require('../../config').activityAppliesUrl;

const minImgDoc = require('../../config').minImgDoc;

const userAvatar = require('../../config').userAvatar;

const loginmanager = require('../../utils/loginManager');

const util = require('../../utils/util.js');

const app = getApp();

export default {
    data() {
        return {
            userAvatar: userAvatar,
            minImgDoc: minImgDoc,
            baseUrl: baseUrl,
            nickname: '',
            datalist: [],
            thread: {},
            tid: '',
            fid: '',
            loading: false,
            pagenum: 1,
            ppp: 10,
            favoriteinfo: '',
            collecttext: '收藏',
            favid: 0,
            sortdefault: false,
            listSortType: '按时间',
            sortListShow: false,
            workinfo: null,
            isShare: false,
            isJoin: false,
            isExpirations: false,
            commentMoreLock: {},

            special_activity: {
                class: '',
                expiration: 0,
                applynumber: '',
                number: '',
                starttimefrom: '',
                starttimeto: '',
                place: '',
                gender: 0,
                uid: '',
                closed: 0
            },

            shareHidden: false,
            hasMore: false,
            special_image: '',
            applylist: '',
            isActivity: '',
            pid: '',
            member_uid: '',
            currentVideo: '',
            is_moving_slider: false,
            currentAudio: '',
            joinShow: false,
            acPostData: '',

            attItem: {
                aid: '',
                newUrl: ''
            },

            imgIndex: 0,

            video: {
                aid: '',
                newUrl: ''
            },

            is_play: '',
            attachment: '',
            listIndex: [],
            current_process: [],
            total_process: '',
            slider_max: '',
            slider_value: '',

            wreply: {
                id: '',
                nickname: false,
                author: ''
            }
        };
    },
    onShow: function () {
        this.commentMoreLock= {};
    },
    onReady() {
        this.videoContext = uni.createVideoContext('detailVideo');
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

        var tid = options.tid;
        this.tid= tid;this.pagenum= 1;

        if (options.type == 'share') {
            this.isShare = true;
        }

        uni.showLoading();
        this.refreshRequest();
        this.setupAudioPlayer();
    },
    /**
     * 分享
     */
    onShareAppMessage: function (res) {
        this.shareHidden= true;
        var title = this.thread.subject ? this.thread.subject : this.nickname + '邀请你参与活动，快快加入吧';
        var path = '/pages/discovery/discovery?shareid=' + this.tid + '&special=' + this.thread.special;
        var imagePath = minImgDoc + '/static/pages/activity_detail/kehoushare.png';

        if (this.datalist[0].imageA.length > 0) {
            imagePath = this.datalist[0].imageA[0].newUrl;
        }

        return {
            title: title,
            path: path,
            imageUrl: imagePath
        };
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {
        this.innerAudioContext.destroy();
    },
    onPullDownRefresh: function () {
        this.refreshRequest();
    },
    onReachBottom: function () {
        if (this.hasMore) {
            this.requestMore(true);
        }
    },
    methods: {
        commentMore(e) {
            var pid = e.currentTarget.dataset.pid;
            var page = this.commentMoreLock[pid];
            var index = e.currentTarget.dataset.index;

            if (typeof page == 'undefined') {
                page = 2;
            }

            var data = {
                pid: pid,
                tid: this.tid,
                page: page
            };
            app.globalData.apimanager
                .getRequest(commentMoreUrl, data)
                .then((res) => {
                    var comments = res.Variables.comments[pid];
                    var usernicknames = res.Variables.usernicknames;

                    if (comments.length > 0) {
                        page++;
                        this.commentMoreLock[pid] = page;

                        for (let key in comments) {
                            let item = comments[key];
                            item.nickname = usernicknames[item.authorid];
                        }

                        this.datalist[index].comments = this.datalist[index].comments.concat(comments);
                        this.commentMoreLock= this.commentMoreLock;this.datalist= this.datalist;
                    } else {
                        this.commentMoreLock[pid] = false;
                        this.commentMoreLock= this.commentMoreLock;
                    }
                })
                .catch((res) => {
                    uni.showToast({
                        title: '出错了！',
                        icon: 'none'
                    });
                });
        },

        makeRequest() {
            this.loading= true;
            let ordertype = 2;

            if (this.sortdefault) {
                this.listSortType= '默认顺序';
                ordertype = 1;
            }

            let getDic = {
                tid: this.tid,
                page: this.pagenum,
                ppp: this.ppp,
                ordertype: ordertype
            };
            app.globalData.apimanager
                .getRequest(detailUrl, getDic)
                .then((res) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    let threads = res.Variables.thread;
                    this.fid = threads.fid;
                    let nickname = res.Variables.member_nickname ? res.Variables.member_nickname : res.Variables.member_username;
                    this.nickname= nickname;

                    if (res.Message) {
                        let messageval = res.Message.messageval;

                        if (
                            messageval.indexOf('nonexistence') != -1 ||
                            messageval.indexOf('nopermission') != -1 ||
                            messageval.indexOf('beoverdue') != -1 ||
                            messageval.indexOf('nomedal') != -1 ||
                            messageval == 'forum_group_noallowed'
                        ) {
                            uni.showModal({
                                title: '提示',
                                content: res.Message.messagestr,
                                showCancel: false,
                                confirmText: '知道了',
                                success: function (res) {
                                    if (res.confirm) {
                                        uni.navigateBack();
                                    }
                                }
                            });
                            return;
                        }
                    }

                    if (threads.favoriteinfo && threads.favoriteinfo != '') {
                        console.log(threads.favoriteinfo);
                        this.favoriteinfo= threads.favoriteinfo;this.favid= threads.favoriteinfo.favid;
                        this.resetCollectState();
                    }

                    var usernicknames = res.Variables.usernicknames;
                    let arr1 = this.datalist;
                    let listArray = res.Variables.postlist;

                    for (let i = 0; i < listArray.length; i++) {
                        let postItem = listArray[i];

                        if (usernicknames) {
                            if (usernicknames[postItem.authorid]) {
                                postItem.nickname = usernicknames[postItem.authorid];
                            }
                        }

                        postItem.message = postItem.message.replace(/\<img/gi, '<img class="rich-img"');
                        postItem.message = postItem.message.replace(/<font (.*?)>/gi, '');
                        postItem.message = postItem.message.replace(/<\/font>/gi, ''); // 作业评论处理

                        let comments = res.Variables.comments;

                        if (comments && comments.length != 0) {
                            if (comments[postItem.pid]) {
                                let comment = comments[postItem.pid];

                                for (let key in comment) {
                                    let item = comment[key];

                                    if (usernicknames) {
                                        item.nickname = usernicknames[item.authorid];
                                    }
                                }

                                postItem.comments = comment;
                            }
                        }

                        var listindex = i + this.datalist.length; // 附件处理

                        let attachments = postItem.attachments;
                        let imageA = [];
                        let audioA = [];
                        let videoA = [];

                        for (let aidKey in attachments) {
                            let attItem = attachments[aidKey];
                            let newUrl = baseUrl + '/' + attItem.url + attItem.attachment;
                            attItem['newUrl'] = newUrl;

                            if (attItem.isimage != 0) {
                                imageA.push(attItem);
                            } else {
                                if (attItem.ext == 'mp3') {
                                    let total_process = '00:00';

                                    if (attItem.description) {
                                        total_process = util.formatTime(parseInt(attItem.description));
                                    }

                                    attItem['toolUse'] = {
                                        attachment: newUrl,
                                        listIndex: listindex,
                                        total_process: total_process
                                    };
                                    audioA.push(attItem);
                                } else {
                                    if (attItem.ext == 'mp4') {
                                        videoA.push(attItem);
                                    }
                                }
                            }
                        }

                        postItem['imageA'] = imageA;
                        postItem['audioA'] = audioA;
                        postItem['videoA'] = videoA;
                    }

                    if (this.pagenum > 1) {
                        arr1 = arr1.concat(listArray);
                    } else {
                        arr1 = listArray;
                    }

                    if (arr1.length - 1 >= threads.replies) {
                        this.hasMore= false;
                    } else {
                        this.hasMore= true;
                    }

                    if (res.Variables.special_activity) {
                        this.special_activity= res.Variables.special_activity;

                        if (this.special_activity.attachurl) {
                            var special_image = baseUrl + '/' + this.special_activity.attachurl;
                            this.special_image= special_image;
                        } else {
                            if (arr1[0].attachments) {
                                var attachments = arr1[0].attachments;

                                for (let aidKey in attachments) {
                                    let attItem = attachments[aidKey];

                                    if (!this.special_image) {
                                        this.special_image= baseUrl + '/' + attItem.url + attItem.attachment;
                                    }
                                }
                            }
                        }

                        if (res.Variables.applylist) {
                            this.applylist= res.Variables.applylist;
                        }

                        var strbutton = this.special_activity.button;
                        var strclosed = this.special_activity.closed;
                        var isActivity = false;

                        if (strbutton == 'join' && strclosed == 0) {
                            isActivity = true;
                        }

                        this.isActivity= isActivity;

                        if (arr1[0].pid) {
                            this.pid= arr1[0].pid;
                        }
                    }

                    this.setData({
                        loading: false,
                        datalist: arr1,
                        thread: threads,
                        member_uid: res.Variables.member_uid
                    });
                })
                .catch((res) => {
                    uni.stopPullDownRefresh();
                    uni.hideLoading();
                    this.loading= false;
                    uni.showToast({
                        title: '出错了！',
                        icon: 'none'
                    });
                });
        },

        showSort() {
            this.sortListShow= !this.sortListShow;
        },

        sortClick(e) {
            let id = e.currentTarget.id;
            let sortdefault = true;
            let listSortType = '默认顺序';

            if (id == 1) {
                sortdefault = false;
                listSortType = '按时间';
            }

            this.pagenum = 1;
            this.setData({
                sortdefault: sortdefault,
                listSortType: listSortType,
                sortListShow: false
            });
            this.makeRequest();
        },

        resetCollectState() {
            let collecttext = this.collecttext;

            if (this.favid != 0) {
                collecttext = '已收藏';
            } else {
                collecttext = '收藏';
            }

            console.log(collecttext);
            this.collecttext= collecttext;
        },

        collectThread() {
            if (this.favid != 0) {
                // 已收藏 取消收藏
                let url = collectUrl + '&op=delete&deletesubmit=yes';
                let formhash = app.globalData.formhash;
                let postData = {
                    formhash: formhash,
                    favid: this.favid
                };
                app.globalData.apimanager
                    .postRequest(url, postData)
                    .then((res) => {
                        if (res.Message.messageval == 'do_success') {
                            this.favoriteinfo= '';this.favid= 0;
                            this.resetCollectState();
                        } else {
                            uni.showToast({
                                title: res.Message.messagestr,
                                icon: 'none'
                            });
                        }
                    })
                    .catch((res) => {
                        uni.showToast({
                            title: '出错了！',
                            icon: 'none'
                        });
                    });
            } else {
                // 未收藏 去收藏
                let formhash = app.globalData.formhash;
                let data = {
                    formhash: formhash,
                    id: this.tid
                };
                app.globalData.apimanager
                    .getRequest(collectUrl, data)
                    .then((res) => {
                        if (res.Message.messageval == 'favorite_do_success') {
                            this.favid= res.Variables.favid;
                            this.resetCollectState();
                        } else {
                            uni.showToast({
                                title: res.Message.messagestr,
                                icon: 'none'
                            });
                        }
                    })
                    .catch((res) => {
                        uni.showToast({
                            title: '出错了！',
                            icon: 'none'
                        });
                    });
            }
        },

        postEnter() {
            if (!loginmanager.isLogin()) {
                return;
            }

            uni.navigateTo({
                url: '../post_thread/post_thread?isreply=true'
            });
        },

        replyWork(e) {
            if (!loginmanager.isLogin()) {
                return;
            }

            uni.navigateTo({
                url: '../post_thread/post_thread?isevaluate=true&pid=' + e.currentTarget.id
            });
        },

        sendFlower(e) {
            let index = parseInt(e.currentTarget.id);
            let replyItem = this.datalist[index];
            let formhash = app.globalData.formhash;
            let data = {
                tid: this.tid,
                pid: replyItem.pid,
                hash: formhash
            };
            app.globalData.apimanager
                .getRequest(sendFlowerUrl, data)
                .then((res) => {
                    if (res.Message.messageval == 'thread_poll_succeed') {
                        if (replyItem.postreview && replyItem.postreview.support) {
                            replyItem.postreview.support = parseInt(replyItem.postreview.support) + 1;
                        } else {
                            var postreview = {
                                support: 1
                            };
                            replyItem['postreview'] = postreview;
                        }

                        let param = {};
                        let str = 'datalist[' + index + ']';
                        param[str] = replyItem;
                        this.setData(param);
                    } else {
                        uni.showToast({
                            title: res.Message.messagestr,
                            icon: 'none'
                        });
                    }
                })
                .catch((res) => {
                    uni.showToast({
                        title: '出错了',
                        icon: 'none'
                    });
                });
        },

        bestanswer(e) {
            var data = {
                tid: this.tid,
                pid: e.currentTarget.id,
                formhash: app.globalData.formhash
            };
            uni.showLoading({
                title: '操作中'
            });
            app.globalData.apimanager
                .postRequest(bestanswerUrl, data)
                .then((res) => {
                    uni.hideLoading();

                    if (res.Message.messageval == 'reward_completion') {
                        this.refreshRequest();
                    }

                    uni.showToast({
                        title: res.Message.messagestr,
                        icon: 'none'
                    });
                })
                .catch((res) => {
                    uni.hideLoading();
                });
        },

        // 播放视频 -------------------
        clickVideo(e) {
            this.currentVideo= e.currentTarget.id;
            this.videoContext.requestFullScreen({
                direction: 0
            });
        },

        fullScreenChange(e) {
            if (!e.detail.fullScreen) {
                this.videoContext.stop();
            }
        },

        /* *********************** 语音相关start *********** */
        setupAudioPlayer() {
            this.innerAudioContext = uni.createInnerAudioContext();
            this.innerAudioContext.obeyMuteSwitch = false;
            this.innerAudioContext.onEnded((res) => {
                this.currentAudio.toolUse.is_ended = true;
                this.stopVoice();
            });
            this.innerAudioContext.onTimeUpdate(() => {
                console.log('ontimeupdate');

                if (!this.is_moving_slider) {
                    // 播放中
                    this.currentAudio = this.datalist[this.currentAudio.toolUse.listIndex].audioA[0];
                    let param = {};
                    let toolUsestr = 'datalist[' + this.currentAudio.toolUse.listIndex + '].audioA[0].toolUse';
                    let toolUse = this.currentAudio.toolUse;
                    toolUse['current_process'] = util.formatTime(this.innerAudioContext.currentTime);
                    toolUse['slider_value'] = Math.floor(this.innerAudioContext.currentTime);
                    toolUse['slider_max'] = Math.floor(this.innerAudioContext.duration);
                    param[toolUsestr] = toolUse;
                    this.setData(param);
                }
            });
        },

        // 拖动进度条，到指定位置
        hanle_slider_change(e) {
            const position = e.detail.value;
            this.seekCurrentAudio(position);
        },

        // 拖动进度条控件
        seekCurrentAudio(position) {
            this.innerAudioContext.seek(position);
        },

        // 进度条滑动
        handle_slider_move_start() {
            this.is_moving_slider= true;
        },

        handle_slider_move_end() {
            this.is_moving_slider= false;
        },

        // 点击播放暂停
        audio_play(e) {
            let listIndex = e.currentTarget.dataset.listindex;
            let postItem = this.datalist[listIndex];
            let currentAudio = postItem.audioA[0];
            var param = {};
            let audioset = 'datalist[' + listIndex + '].audioA[0].toolUse.currentAudio';
            param[audioset] = currentAudio.newUrl;
            this.setData(param);
            this.currentAudio= currentAudio;
            let isplay = this.currentAudio.toolUse.is_play;
            let playstr = 'datalist[' + listIndex + '].audioA[0].toolUse.is_play';
            param[playstr] = !isplay;
            this.setData(param);

            if (isplay) {
                this.innerAudioContext.pause();
                isplay = false;
            } else {
                if (!isplay && !this.currentAudio.toolUse.is_ended) {
                    this.playVoice();
                } else {
                    this.innerAudioContext.play();
                }
            }
        },

        playVoice() {
            var src = this.currentAudio.newUrl;
            this.innerAudioContext.src = src;
            this.innerAudioContext.play();
        },

        stopVoice() {
            var param = {};
            let toolUsestr = 'datalist[' + this.currentAudio.toolUse.listIndex + '].audioA[0].toolUse';
            let toolUse = this.currentAudio.toolUse;
            toolUse['is_play'] = false;
            toolUse['slider_value'] = 0;
            toolUse['current_process'] = util.formatTime(0);
            param[toolUsestr] = toolUse;
            this.setData(param);
            this.innerAudioContext.stop();
            this.currentAudio = this.datalist[this.currentAudio.toolUse.listIndex].audioA[0];
        },

        /* *********************** 语音end *********** */
        lookImage(e) {
            let cellItem = this.datalist[e.currentTarget.dataset.cellindex];
            let imageA = cellItem.imageA;
            var imageSrcArray = [];

            for (let i = 0; i < imageA.length; i++) {
                let item = imageA[i];
                imageSrcArray.push(item.newUrl);
            }

            console.log(imageSrcArray);
            uni.previewImage({
                current: imageSrcArray[e.currentTarget.id],
                urls: imageSrcArray
            });
        },

        requestMore(isMore) {
            let pagenum = this.pagenum;

            if (isMore) {
                pagenum += 1;
            } else {
                pagenum = 1;
            }

            this.pagenum= pagenum // 更新当前页数;
            this.makeRequest(); // 重新调用请求获取下一页数据 或者刷新数据
        },

        refreshRequest() {
            this.requestMore(false);
        },

        replyText() {
            if (!loginmanager.isLogin()) {
                return;
            }

            uni.navigateTo({
                url: '../post_thread/post_thread?isreply=true&type=text'
            });
        },

        joinActivity() {
            if (this.special_activity.closed == 1) {
                return;
            }

            var acPostData = {
                fid: this.fid,
                tid: this.tid,
                pid: this.pid,
                formhash: app.globalData.formhash
            };

            if (this.isActivity) {
                this.joinShow= true;this.acPostData= acPostData;
            } else {
                acPostData['activitycancel'] = true;
                app.globalData.apimanager
                    .postRequest(activityAppliesUrl, acPostData)
                    .then((res) => {
                        if (res.Message.messageval.indexOf('_success') != -1) {
                            this.refreshRequest();
                        }

                        uni.showModal({
                            content: res.Message.messagestr,
                            showCancel: false,
                            confirmText: '知道了'
                        });
                    })
                    .catch((res) => {});
            }
        },

        joinSucceed() {
            this.refreshRequest();
        },

        activityManage() {
            uni.navigateTo({
                url: '../activity_signup/activity_signup?tid=' + this.tid + '&pid=' + this.pid
            });
        },

        cellClick() {
            console.log('占位：函数 cellClick 未声明');
        },

        share() {
            console.log('占位：函数 share 未声明');
        }
    }
};
</script>
<style>
@import './activity_detail.css';
</style>
